<?php


namespace app\api\controller;


use app\api\logic\LoginLogic;
use app\api\validate\LoginValidate;
use app\common\controller\BaseApiController;
use common\service\JwtService;

/**
 * 用户登录管理
 * Class UserController
 * @package app\api\controller
 */
class LoginController extends BaseApiController
{
    protected $noNeedLogin = ['*'];

    protected function init()
    {
        parent::init();
        $this->logic = new LoginLogic();
        $this->validate = new LoginValidate();
    }

    /**
     * 账号密码登录
     */
    public function loginByAccount()
    {
        $this->validate->checkData(input(), 'loginByAccount');
        return $this->success($this->logic->loginByAccount(input()));
    }

    /**
     * 手机+验证码登录
     */
    public function loginByMobile()
    {
        $this->validate->checkData(input(), 'loginByMobile');
        return $this->success($this->logic->loginByMobile(input()));
    }


    public function loginOut()
    {
        JwtService::logout('api');
        return $this->success();
    }

    /**
     * 微信公众号code登录
     */
    public function loginByCode()
    {
        $code = trim(input('code'));
        $invite_id = trim(input('invite_id', 0));
        $user = $this->logic->loginByCode($code, $invite_id);

        return $this->success($user);
    }
}